package ve.com.ucv.changedetection.tools;

import org.apache.log4j.Logger;
import ve.com.ucv.changedetection.objects.Constants;

import java.io.IOException;
import java.security.PublicKey;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: josmaguirre
 * Date: 1/22/13
 * Time: 10:22 AM
 * To change this template use File | Settings | File Templates.
 */
public class Weights {
    //public static Logger logger = Logger.getLogger(Weights.class);
    public static HashMap<String,Integer> weights = new HashMap<String, Integer>();

    static{
        Properties properties = new Properties();
        try{
            properties.load(Weights.class.getClassLoader().getResourceAsStream(Constants.PROPERTIES_NAME));
            Enumeration e = properties.propertyNames();
            while(e.hasMoreElements()){
                String key = e.nextElement().toString();
                int value = Integer.parseInt(properties.getProperty(key));
                weights.put(key,value);
            }

        }catch(IOException e){
            e.printStackTrace();
        }
    }

    public static HashMap<String, Integer> getWeights() {
        return weights;
    }

    public static void setWeights(HashMap<String, Integer> weights) {
        Weights.weights = weights;
    }

    public static boolean isInWeights(String name){
        return getWeights().containsKey(name);
    }

    public static int getattributeWeight(String name){
        if (getWeights().containsKey(name.toLowerCase()))
            return getWeights().get(name.toLowerCase());
        else
            return 1;
    }
}
